<?php
/**
 * 通过卡券自定义外链进入其他页面后解码真实code（用来使用）
 */
require_once('common.php');

$decrypt_url = 'https://api.weixin.qq.com/card/code/decrypt?access_token=';
$access_token = get_access_token();

$encrypt_code = trim($_GET['encrypt_code']);
if(empty($encrypt_code)){
    echo_Json(-1, '加密code码不能为空');
}

//'jNxG%2B00ykNmOTYOz3WsBiCt%2FFGXqLhkO%2B4Ay%2BUuW3EY%3D'
$postData = array(
    'encrypt_code' => $encrypt_code  //真实code：763711247967
);
$true_codeArr = decrypt_code($decrypt_url.$access_token, $postData);
if($true_codeArr['code'] != 0){
    echo_Json($true_codeArr['code'], '解码失败');
}else{
    $data['true_code'] = $true_codeArr['true_code'];
    echo_Json($true_codeArr['code'], '解码成功', $data);
}

function decrypt_code($url, $data){
    $code_Arr = jsonpostJson($url, $data, true);
    if($code_Arr['errcode'] != 0){
        $result = array(
            'code' => $code_Arr['errcode'],
        );
    }else{
        $result = array(
            'code' => 0,
            'true_code'  => $code_Arr['code'],       
        );
    }
    return $result;
}